import os
from file_tools.remove_duplicate_files import Cleaner
from config.logger_config import init_logger
from file_tools.windows_cleaner import WindowsCleaner

logger = init_logger()


def input_with_default(prompt, default):
    user_input = input(f"{prompt} (default: {default}): ")
    if user_input == "":
        return default
    return user_input


if __name__ == "__main__":

    print('==============欢迎使用=================')
    while True:
        print('1.去除重复文件')
        print('2.清理c盘')
        print('q.退出')
        selection = input('选择你的操作：')
        if selection == '1':
            target_clean_folder = input('请输入目标文件夹：')
            if not os.path.exists(target_clean_folder):
                logger.error(f'your target folder "{target_clean_folder}" not exist')
                continue
            clean_in_recursion = input_with_default('要递归删除吗(n)：', 'n')
            if clean_in_recursion == 'n':
                Cleaner(target_clean_folder).remove_duplicates()
            elif clean_in_recursion == 'y':
                Cleaner(target_clean_folder).remove_duplicates_recursion()
        if selection == '2':
            WindowsCleaner().scan_cache()
        elif selection == 'q':
            break
        else:
            print('请输入正确的值')
